#!/usr/bin/python
# -*- coding: UTF-8 -*-

from kpautos.engine.case import Case
from kptest.config.enum import DeviceType, HostType, DeviceUtility


class MockAlarm_CLI_034(Case):
    """
        Name:
            MockAlarm_CLI_034
        Label:
            告警配置验证
        PreCondition:
            1、BMC正常运行
            2、OS正常运行
        TestStep:
            1、登录CLI，发送”ipmcset -t precisealarm -d mock -v 0x03000007 assert”
            2、查看健康信息，有结果A）
            3、查看sel日志，有结果B）
        ExpectedResult:
            A）告警描述有[Mock]字样
            B）SEL日志中事件描述有[Mock]字样
        Parameters:

        Remark:

    """

    # 测试执行前配置等准备操作
    def pre_test_case(self):
        self.device_dut = self.resource.get_device(device_type=DeviceType.Server, utility=DeviceUtility.DUT)
        self.os_host = self.device_dut.get_host(host_type=HostType.HostOS)
        self.cli_api = self.device_dut.get_api(ns_name="BmcCli")

    # 测试步骤
    def procedure(self):
        self.log_step("1、登录CLI，发送”ipmcset -t precisealarm -d mock -v 0x03000007 assert”")
        self.cli_api.cli_simulate_events(option='0x03000007', eventstatus='assert')

        self.log_step("2、查看健康信息，有结果A）")
        alarm_info = self.cli_api.cli_query_system_health_event()
        for data in alarm_info:
            if '0x03000007' in str(data) and '[Mock]' in str(data):
                self.logger.info("A）告警描述有[Mock]字样")
                break
        else:
            raise Exception("告警信息不符合预期")


        self.log_step("3、查看sel日志，有结果B）")
        sel_info = self.cli_api.cli_query_clear_sel(method='query', option='list')
        for event in sel_info.get('information'):
            if event.get('event_code') == '0x03000007' and '[Mock]' in event.get('event_description'):
                self.logger.info("B）SEL日志中事件描述有[Mock]字样")
                break
        else:
            raise Exception("sel日志信息不符合预期")


    # 测试结束后恢复环境
    def post_test_case(self):
        pass
